<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<link href="<%=request.getContextPath()%>/static/plugin/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/static/plugin/zTree/js/jquery.ztree.all-3.5.min.js"></script>
<style type="text/css">
#content {
        position: absolute;
        top: 0;
        left: 240px;
        right: 10px;
        bottom: 0;
        box-sizing: border-box;
    }
    ul.ztree {
       width: 230px;
    }
</style>

</head>
<body class="iframe-page">
  <!-- 左侧菜单显示 -->
	<div class="tree-wrap">
	    <div class="tree-title">组织机构列表</div>
	    <div class="tree-content">
		  	<!-- 拼接树 -->
		    <ul id="categoryTree" class="ztree"></ul>
		</div>
	</div>
    
    <!-- 右侧拼接页面 -->
	<div id="content">
	    <iframe id="categoryFrame" frameborder="0" style="width: 100%;height: 100%" src="<%=request.getContextPath()%>/mall/system/goods/goodsspu/initGoodsSpu?codeId=000"></iframe>
	</div>
    
    <!-- 鼠标右键 -->
    <div id="resourceMenu" style="width:140px;">
	      <div id="add">新建子节点</div>
	      <div id="edit">编辑节点</div>
	      <div id="delete">删除节点</div>
    </div>
    
<script>

	//请求url
	var GOODS_CATEGORY_URL = {
		INIT_GOODSCATEGORY: basePath + '/mall/system/goods/goodsspu/initGoodsSpu',
		GET_TREE: basePath + "/sys/inner/getCategoryTree"
	};

	var categoryFrame = document.getElementById("categoryFrame"),ztree;
	
	
	//初始化组织机构树
	function initOrgTree(treeId, url,idKey, pIdKey) {
		var setting = {
	        data: {
	            simpleData: {
	                enable: true,
	                idKey: idKey,
                    pIdKey: pIdKey
	            }
	        },
	        edit: {
	            enable: false,
	            drag: {
	                isMove: false
	            }
	        },
	        callback: {
	            onClick: selectUserByOrgCode,
	        }
	    };
	    
	    $.sajax({
	        url: url,
	        onLoadSuccess: function(data) {
	            ztree = $.fn.zTree.init($('#' + treeId),setting,data.data);
	            expandNode();
	        }
	    });
	}
	
	$(function () {
		//初始化左侧组织机构树
		initOrgTree('categoryTree', GOODS_CATEGORY_URL.GET_TREE, 'codeid', 'pid');
		
		 $('#resourceMenu').menu({
             onClick: function(item){
             	if (item.id == 'add') {
             		addResource(currentNode);
             	} else if (item.id == 'edit') {
             		editResource(currentNode);
             	} else if (item.id == 'delete') {
             		deleteResource(currentNode);
             	}
             }
         }); 
	});
	
	
	
	// 展开树节点
	function expandNode() {
		var nodeCode = '${param.expandId}',node;
		if (nodeCode) {
		   // 获取需要自动展开的节点
		   node = ztree.getNodeByParam('codeid', nodeCode, null);
		} else {
		   // nodeId为空,展开根节点
		   node = ztree.getNodeByParam('pid', null, null);
		}
		// 如果该节点不包含子节点,则展开其父节点
		if (node && !node.isParent) {
		  node = node.getParentNode(); 
		}
		ztree.expandNode(node, true, false, true);
	}
	
    
	
    // 刷新页面, nodeId为初始化页面时需要自动展开的节点ID
    function refreshPage(nodeId, continueAdd, level) {
   	 nodeId = nodeId || '';
    	 if (continueAdd){
    		var node = ztree.getNodeByParam("pid", nodeId, null);
    		ztree.setting.async.url = GOODS_CATEGORY_URL.GET_TREE + "?pid=" + nodeId;
    		node.isParent = true,
           ztree.updateNode(node);
    		ztree.reAsyncChildNodes(node, "refresh");
    	 } else {
    	    location.href = GOODS_CATEGORY_URL.INIT_MAIN+'?pid='+nodeId;
    	 }
    }
    
    
	//点击组织机构树查询用户
	function selectUserByOrgCode(event, treeId, treeNode) {
		
		url = GOODS_CATEGORY_URL.INIT_GOODSCATEGORY + "?pid=" + treeNode.pid+"&codeid="+treeNode.codeid+"&categoryName="+treeNode.name;
		categoryFrame.src = url; 
		//选中节点
		ztree.selectNode(treeNode);
	}
	
	//阻止默认的右键菜单
	function forbidRightMenu(event, treeId, treeNode) {
		document.oncontextmenu = function (){
		   return false;
		};
	}
	
	
</script>
</body>
</html>